package org.ns.longhttp.arguments;

import java.util.HashMap;
import java.util.Map;

public class Arguments {

    private String[] args;
    private Map<String, String> attributes = new HashMap<>();
    public Arguments(String[] args) {
        this.args = args;

        for (String arg : args) {
            int index = arg.indexOf("=");
            if (index != -1) {
                String key = arg.substring(0, index);
                String val = arg.substring(index + 1);
                attributes.put(key, val);
            }
        }
    }
    public String get(String name) {
        return attributes.get(name);
    }

    public int getIntValue(String name, int def) {
        Integer value = getInt(name);
        if (value == null) {
            value = def;
        }
        return value;
    }
    public Integer getInt(String name) {
        String value = get(name);
        if (value == null || (value = value.trim()).isEmpty()) {
            return null;
        }
        return Integer.parseInt(value);
    }
}
